<?php
/**
 * @version 0.8.3 2010-10-07
 * @package Joomla
 * @subpackage LeagueResults
 * @copyright (C)  2008, 2009, 2010 Henryk Drozd
 * @license GNU/GPL, see LICENSE.php
 * LeagueResults is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2
 * as published by the Free Software Foundation.

 * LeagueResults is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */


defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.html.pane');
jimport( 'joomla.application.component.view');


class lrViewEditcss extends JView {

	function display($tpl = null)
	{
		global $mainframe;

		// Initialize some variables
		$option		= JRequest::getCmd('option');

		$fname	= JRequest::getVar('css_file');
		$filename   = JPATH_COMPONENT_SITE.DS.'assets'.DS.'css'.DS.$fname;
		
		jimport('joomla.filesystem.file');

		if (JFile::getExt($filename) !== 'css') {
			$msg = JText::_('Wrong file type given, only CSS files can be edited.');
			$mainframe->redirect('index.php?option='.$option, $msg, 'error');
		}

		$content = JFile::read($filename);

		if ($content !== false)
		{
			// Set FTP credentials, if given
			jimport('joomla.client.helper');


			$content = htmlspecialchars($content, ENT_COMPAT, 'UTF-8');

			$this->editcssSource($fname, $filename, $content);
		}
		else
		{
			$msg = JText::sprintf('Operation Failed Could not open', $client->path.$filename);
			$mainframe->redirect('index.php?option='.$option, $msg);
		}
	}

	
	
	function editcssSource($fname, $filename, & $content)
	{
		JRequest::setVar( 'hidemainmenu', 1 );

		JToolBarHelper::title( '<img src="components/com_lr/assets/images/lr1.jpg" height="30" width="75" alt="League Results Logo" valign="middle" /> '. JText::_( 'EDIT CSS' ), 'cssedit' );

		JToolBarHelper::apply();
		JToolBarHelper::spacer();
		JToolBarHelper::save();
		JToolBarHelper::spacer();
		JToolBarHelper::cancel();
		JToolBarHelper::spacer();

		$this->assignRef('filename'      	, $filename);
		$this->assignRef('fname'      	, $fname);
		$this->assignRef('content'      	, $content);
		
		parent::display($tpl);

	}
}
?>